/*objlot.java
*
* Created on Sat Mar 22 20:04:32 BRT 2008
*
*/

package rad.Java.Camping.Class;

import rad.Java.Common.Database;
import javax.swing.JOptionPane;
import java.sql.*; 
import rad.Java.Common.DataSet;

public class Lot 
 { 

   public Lot(Database database) {

        this.database = database;
    }

    /*Atributes*/
    private Database database;
    private ResultSet resultset;
    private int lot_id;
    private String lot_name;
    private String lot_state;
    private boolean lot_active;


    /*Properties*/
    public void setlot_id(int value) {
        this.lot_id = value;
    }

    public int getlot_id() {
        return this.lot_id;
    }

    public void setlot_name(String value) {
        this.lot_name = value;
    }

    public String getlot_name() {
        return this.lot_name;
    }

    public void setlot_state(String value) {
        this.lot_state = value;
    }

    public String getlot_state() {
        return this.lot_state;
    }

    public void setlot_active(boolean value) {
        this.lot_active = value;
    }

    public boolean getlot_active() {
        return this.lot_active;
    }

    /*Methods*/
    public boolean Get() {

        String sql;
        try {
            sql = " SELECT lot_id, lot_name, lot_state, lot_active FROM lot  WHERE (lot_id = " + lot_id + ")";
            resultset = database.executeQueryRs(sql);
            resultset.next();
            lot_name = resultset.getString("lot_name");
            lot_state = resultset.getString("lot_state");
            lot_active = resultset.getBoolean("lot_active");
            return true;
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
            return false;
        }
    }

    public boolean Save() {

        String sql;
        try {
            sql = " INSERT INTO lot(lot_name, lot_state, lot_active) VALUES(" + lot_name + "', '" + lot_state + "', '" + lot_active + "')";
            database.executeCommand(sql, database.doNotUseTransaction);
            if (database.Error) {
                JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + database.ErrorMessage);
                return false;
            } else {
                JOptionPane.showMessageDialog(null, "Opera??o efetuada com sucesso! ");
                return true;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
            return false;
        }
    }

    public boolean Update() {

        String sql;
        try {
            sql = " UPDATE lot SET (" + " , " + "lot_name = " + "'" + lot_name + "'" + " , " + "lot_state = " + "'" + lot_state + "'" + " , " + "lot_active = " + "'" + lot_active + "'" + " )" + " WHERE (" + "lot_id = " + lot_id + ")";
            database.executeCommand(sql, database.doNotUseTransaction);
            if (database.Error) {
                JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + database.ErrorMessage);
                return false;
            } else {
                JOptionPane.showMessageDialog(null, "Opera??o efetuada com sucesso! ");
                return true;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
            return false;
        }
    }

    public boolean Delete() {

        String sql;
        try {
            sql = " DELETE FROM lot" + " WHERE (" + "lot_id = " + lot_id + ") AND (" + "lot_name = " + "'" + lot_name + "') AND (" + "lot_state = " + "'" + lot_state + "') AND (" + "lot_active = " + "'" + lot_active + "')";
            database.executeCommand(sql, database.doNotUseTransaction);
            if (database.Error) {
                JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + database.ErrorMessage);
                return false;
            } else {
                JOptionPane.showMessageDialog(null, "Opera??o efetuada com sucesso! ");
                return true;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
            return false;
        }
    }

    public DataSet Search() {

        DataSet ds;
        String sql;
        try {
            sql = " SELECT lot_id, lot_name, lot_state, lot_active FROM lot ";
            ds = database.executeQuery(sql);
            if (database.Error) {
                return null;
            } else {
                return ds;
            }
        } catch (Exception ex) {
            return null;
        }
    }

 } 